using Crawler.Domain.DataEntities;
using Crawler.Domain.DataEntities.Extracted;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;

namespace Crawler.DataServices.Persistence.nHibernate.Conventions
{
	public class UniqueConvention : IPropertyConvention
	{
		private const string MovieUniqueName = "MovieUnique";

		public void Apply(IPropertyInstance instance)
		{
			if (instance.EntityType == typeof (Movie) && (instance.Name == "Title" || instance.Name == "Year"))
				instance.UniqueKey(MovieUniqueName);
			else if (instance.EntityType != typeof (SubtitleFile) &&
			         instance.EntityType != typeof (CrawlingSession) &&
			        ( instance.Name == "FromUrl"|| instance.Name=="SessionId"))
				instance.UniqueKey("UrlUnique");
		}
	}
}